package webapp;

import java.util.ArrayList;
import java.util.List;

import mda.type.IBaseType;
import mda.type.IEntityType;
import mda.type.IServiceType;
import flca.mda.codegen.data.ITemplate;
import flca.mda.codegen.data.Template;
import flca.mda.codegen.data.TemplateMergeStrategy;

public class ZkConstants implements TemplatesConstBase {
	
	public static final String CARTRIDGE_NAME = "webapp-zk";

	protected static final String Backend = LE + WebappConstants.BACKEND + RI;
	protected static final String Frontend = LE + WebappConstants.FRONTEND_ZK + RI;

	public Tid[] getTemplates() {
		return new Tid[] { Tid.ZK_DETAIL_CTRL, Tid.ZK_DETAIL_VIEW, Tid.ZK_MAINT_CTRL, Tid.ZK_MAINT_VIEW,
				Tid.ZK_SERVICE_FACT, Tid.ZK_SERVICE_MOCK, Tid.ZK_SERVICE_BIND, Tid.ZK_INDEX_CTRL, Tid.ZK_SESSION_STATE, };
	}

	private static List<ITemplate> allTemplates;

	public ZkConstants() {
		super();
		if (allTemplates == null) {
			allTemplates = makeTemplates();
		}
	}

	@Override
	public List<ITemplate> getAllTemplates() {
		return allTemplates;
	}

	public List<ITemplate> makeTemplates() {
		List<ITemplate> result = new ArrayList<ITemplate>();

		result.add(makeTemplate_ZK_DETAIL_CTRL());
		result.add(makeTemplate_ZK_DETAIL_VIEW());
		result.add(makeTemplate_ZK_MAINT_CTRL());
		result.add(makeTemplate_ZK_MAINT_VIEW());
		result.add(makeTemplate_ZK_SERVICE_FACT());
		result.add(makeTemplate_ZK_SERVICE_MOCK());
		result.add(makeTemplate_ZK_SERVICE_BIND());
		result.add(makeTemplate_ZK_INDEX_CTRL());
		result.add(makeTemplate_ZK_SESSION_STATE());
		
		return result;
	}

	private ITemplate makeTemplate_ZK_DETAIL_CTRL() {
		Template r = new Template();
		r.setName(Tid.ZK_DETAIL_CTRL.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>DetailCtrl");
		r.setTargetDir("<%=FrontendZk%>/<%=src-gen%>");
		r.setFileExtension(".java");
		r.setGeneratorFqn(frontend.zk.ZkDetailCtrl.class.getName());
		r.setJetPath("/frontend/zk/ZkDetailCtrl.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.JAVA_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_ZK_DETAIL_VIEW() {
		Template r = new Template();
		r.setName(Tid.ZK_DETAIL_VIEW.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>DetailView");
		r.setTargetDir("<%=FrontendZk%>/<%=web%>");
		r.setFileExtension(".zul");
		r.setGeneratorFqn(frontend.zk.ZkDetailView.class.getName());
		r.setJetPath("/frontend/zk/ZkDetailView.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.JAVA_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_ZK_MAINT_CTRL() {
		Template r = new Template();
		r.setName(Tid.ZK_MAINT_CTRL.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>MaintCtrl");
		r.setTargetDir("<%=FrontendZk%>/<%=src-gen%>");
		r.setFileExtension(".java");
		r.setGeneratorFqn(frontend.zk.ZkMaintCtrl.class.getName());
		r.setJetPath("/frontend/zk/ZkMaintCtrl.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_ZK_MAINT_VIEW() {
		Template r = new Template();
		r.setName(Tid.ZK_MAINT_VIEW.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>MaintView");
		r.setTargetDir("<%=FrontendZk%>/<%=web%>");
		r.setFileExtension(".zul");
		r.setGeneratorFqn(frontend.zk.ZkMaintView.class.getName());
		r.setJetPath("/frontend/zk/ZkMaintView.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.SKIP);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IEntityType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_ZK_SERVICE_FACT() {
		Template r = new Template();
		r.setName(Tid.ZK_SERVICE_FACT.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>Fact");
		r.setTargetDir("<%=FrontendZk%>/<%=src-gen%>");
		r.setFileExtension(".java");
		r.setGeneratorFqn(frontend.zk.ZkServiceFact.class.getName());
		r.setJetPath("/frontend/zk/ZkServiceFact.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.JAVA_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_ZK_SERVICE_MOCK() {
		Template r = new Template();
		r.setName(Tid.ZK_SERVICE_MOCK.name());
		r.setPackage("<%=PACKAGE%>");
		r.setClassname("<%=CLASSNAME%>Mock");
		r.setTargetDir("<%=FrontendZk%>/<%=src-gen%>");
		r.setFileExtension(".java");
		r.setGeneratorFqn(frontend.zk.ZkServiceMock.class.getName());
		r.setJetPath("/frontend/zk/ZkServiceMock.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.JAVA_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_ZK_SERVICE_BIND() {
		Template r = new Template();
		r.setName(Tid.ZK_SERVICE_BIND.name());
		r.setPackage("<%=App-package%>");
		r.setClassname("<%=App-name%>Module");
		r.setTargetDir("<%=Backend%>/<%=src-gen%>");
		r.setFileExtension(".java");
		r.setGeneratorFqn(frontend.zk.ZkServiceBind.class.getName());
		r.setJetPath("/frontend/zk/ZkServiceBind.asjet");
		r.setInsertionTag("#INSERT_SERVICE_BINDS");
		r.setMergeStrategy(TemplateMergeStrategy.JAVA_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IServiceType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_ZK_INDEX_CTRL() {
		Template r = new Template();
		r.setName(Tid.ZK_INDEX_CTRL.name());
		r.setPackage("<%=App-package%>");
		r.setClassname("<%=App-name%>IndexCtrl");
		r.setTargetDir("<%=FrontendZk%>/<%=src-gen%>");
		r.setFileExtension(".java");
		r.setGeneratorFqn(frontend.zk.ZkIndexCtrl.class.getName());
		r.setJetPath("/frontend/zk/ZkIndexCtrl.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.JAVA_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IBaseType.class,});
		r.setRank(5);
		return r;
	}

	private ITemplate makeTemplate_ZK_SESSION_STATE() {
		Template r = new Template();
		r.setName(Tid.ZK_SESSION_STATE.name());
		r.setPackage("<%=App-package%>");
		r.setClassname("<%=App-name%>SessionState");
		r.setTargetDir("<%=FrontendZk%>/<%=src-gen%>");
		r.setFileExtension(".java");
		r.setGeneratorFqn(frontend.zk.ZkSessionState.class.getName());
		r.setJetPath("/frontend/zk/ZkSessionState.asjet");
		r.setMergeStrategy(TemplateMergeStrategy.JAVA_MERGE);
		r.setCartridgeName(CARTRIDGE_NAME);
		r.setApplyToClasses(new Class<?> [] {IBaseType.class,});
		r.setRank(5);
		return r;
	}

	public static ITemplate getTemplate(Tid aTid) {
		if (allTemplates == null) {
			new ZkConstants();
		}

		for (ITemplate t : allTemplates) {
			if (t.getName().equals(aTid.name())) {
				return t;
			}
		}
		return null;
	}


}
